package provider

import (
	"fmt"
	"ginfwk/infrastructure/component/config"
	"ginfwk/infrastructure/component/queue"
	"ginfwk/infrastructure/component/queue/adapter"
	di "github.com/samber/do"
)

func RegisterQueue() {
	di.Provide(di.DefaultInjector, func(*di.Injector) (queue.Queue, error) {
		var currentQueue queue.Queue

		cfg := config.Global().Queue
		switch cfg.QueueType {
		case "rabbitmq":
			fallthrough
		case "amqp":
			currentQueue = adapter.NewAmqpAdapter(cfg)
		default:
		}
		if currentQueue == nil {
			return nil, fmt.Errorf("not support queue type: [%s]\n", cfg.QueueType)
		}
		return currentQueue, nil
	})
}
